<template>
	<view class="content" style="padding-bottom: 150rpx;">
		<!-- 頭部 -->
		<view class="header paddinglr">
			<!-- 未登錄 -->
			<view class="flexbetween" @click="goLogin" v-if="!is_login">
				<view class="flex">
					<view class="avtarBox margin_right2">
						<image src="/static/goods.png" mode=""></image>
					</view>
					<view class="flexcenter">
						<view class="color_ling text_weight">去登錄</view>
					</view>
				</view>
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
			<!-- 用戶信息 -->
			<view class="flexbetween" @click="goPersonInformation" v-if="is_login">
				<view class="flexleft">
					<view class="avtarBox margin_right2">
						<image :src="userInfo.avatar" mode=""></image>
					</view>
					<view class="color_ling text_weight">{{userInfo.nickname}}</view>
					<!-- <view>
						<view class="color_ling text_weight">{{userInfo.nickname}}</view>
						<view class="color_six text_d margin_top2">{{userInfo.mobile}}</view>
					</view> -->
				</view>
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
			<view class="flexbetween mainpadding border_top margin_top">
				<!-- 點擊付款掃碼 -->
				<view class="flexcolumn" @click="jumpurlfukuan('/pages_mine/fukuanm')">
					<image src="../../static/images/mine/fukuan.png" class="bannerimg" mode=""></image>
					<view class="xiaohei bold titletext margin_top1">付款</view>
				</view>
				<view class="flexcolumn" @click="shoukuan()">
					<image src="../../static/images/mine/shoukuan.png" class="bannerimg" mode=""></image>
					<view class="xiaohei bold titletext margin_top1">收款</view>
				</view>
				<view class="flexcolumn" @click="goRecharge">
					<image src="../../static/images/mine/chongzhi.png" class="bannerimg" mode=""></image>
					<view class="xiaohei bold titletext margin_top1">儲值點數</view>
				</view>
				<view class="flexcolumn" @click="goWithdrawal">
					<image src="../../static/images/mine/tixian.png" class="bannerimg" mode=""></image>
					<view class="xiaohei bold titletext margin_top1">提領</view>
				</view>
			</view>
			<!-- <image src="@/static/ticket.png" class="bannner margin_top" mode=""></image> -->
			<!-- 收藏、票券、優惠券、瀏覽記錄 -->
			<view class="tabBox flexbetween text">
				<view class="flexleft">
					<view class="margin_right3" @click="goMineCollect">
						<view class="color_ling text_w">{{numAll.sc || 0}}</view>
						<view class="color_six text_five margin_top1">我的收藏</view>
					</view>
					<view class="line"></view>
				</view>
				<view class="flexleft" @click="goTickets">
					<view class="margin_right3">
						<view class="color_ling text_w">{{numAll.pj || 0}}</view>
						<view class="color_six text_five margin_top1">我的票券</view>
					</view>
					<view class="line"></view>
				</view>
				<view class="flexleft">
					<view class="margin_right3" @click="goMineCoupon">
						<view class="color_ling text_w">{{numAll.yhj || 0}}</view>
						<view class="color_six text_five margin_top1">我的優惠券</view>
					</view>
					<view class="line"></view>
				</view>
				<view class="flexleft">
					<view @click="gomianyun">
						<view class="color_ling text_w">{{numAll.myj || 0}}</view>
						<view class="color_six text_five margin_top1">我的免運券</view>
					</view>
				</view>
			</view>
			<image :src="bannerimgdata.image_text" class="bannner margin_top" mode="" @click="zdyclick(bannerimgdata.url)"></image>
		</view>
		<!-- 列表 -->
		<view class="actionBox paddinglr">
			<view class="paddinglr ffffff border">
				<!-- <view class="flexleft">
					<view @click="">
						<view class="color_ling text_w">20</view>
						<view class="color_six text_five margin_top1">我的免運券</view>
					</view>
				</view> -->
				<view class="actionItem flexbetween line_b9" @click="goFootprint">
					<view class="flexleft">
						<image class="listImg" src="/static/images/mine/wallet.png" mode=""></image>
						<view class="color_san text_d">瀏覽記錄</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="actionItem flexbetween line_b9" @click="goAssetManagement">
					<view class="flexleft">
						<image class="listImg" src="/static/images/mine/wallet.png" mode=""></image>
						<view class="color_san text_d">資產管理</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="actionItem flexbetween line_b9" @click="jumpurl('/pages_mine/wodecz')">
					<view class="flexleft">
						<image class="listImg" src="/static/images/mine/wallet.png" mode=""></image>
						<view class="color_san text_d">我的儲值</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="actionItem flexbetween line_b9" @click="goInvoice">
					<view class="flexleft">
						<image class="listImg" src="/static/images/mine/invoice.png" mode=""></image>
						<view class="color_san text_d">發票</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="actionItem flexbetween line_b9"  @click="kefushow=true">
					<view class="flexleft">
						<image class="listImg" src="/static/images/mine/kefu.png" mode=""></image>
						<view class="color_san text_d">我的客服</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="actionItem flexbetween line_b9" @click="goShopSettle">
					<view class="flexleft">

						<image class="listImg" src="/static/images/mine/shop.png" mode=""></image>
						<view class="color_san text_d">商家入駐/進入</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="actionItem flexbetween line_b9" @click="goDeliverySettle">
					<view class="flexleft">
						<image class="listImg" src="/static/images/mine/delivery.png" mode=""></image>
						<view class="color_san text_d">外送員入駐</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="actionItem flexbetween line_b9" @click="goSetUp">
					<view class="flexleft">
						<image class="listImg" src="/static/images/mine/setUp.png" mode=""></image>
						<view class="color_san text_d">設置</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="actionItem flexbetween line_b9" @click="jumpurl('/pages/caozuoshouce/shiyongsc?type=2')">
					<view class="flexleft">
						<image class="listImg" src="/static/images/mine/setUp.png" mode=""></image>
						<view class="color_san text_d">操作手冊</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
			</view>
		</view>
		<u-popup :show="show" mode="center" :round="15" @close="show=false" v-if="is_login">
			<view class="popupBox text">
				<image class="headerImg" src="/static/images/mine/paymentHeader.png" mode=""></image>
				<view class="color_ling text_five">{{userInfo.nickname}}</view>
				<view class="flexcenter margin_top2">
					<uqrcode ref="uqrcode" canvas-id="qrcode" v-bind:value="qrcodeurl_text" :options="{ margin: 10}"
						size="180">
					</uqrcode>
				</view>
				<view class="color_jiu text_g margin_top">長按保存到手機</view>
			</view>
		</u-popup>
		<u-popup :show="kefushow" @close="kefushow=false" mode="center" :round="10">
			<view class="" style="padding: 40rpx;background-color: #fafafa; min-width: 500rpx; border-radius: 40rpx;">
				<view class="titletext bold hei_text flexcenter">聯係客服</view>
				<view class="flexbetween mainpadding ffffff" style="margin-top: 40rpx;" @click="kfgo()">
					<view class="flexleft">
						<image src="../../static/images/system/my5.png" mode="" class="headimg margin_right"></image>
						<view class="">
							<view class="titletext bold hei_text">Line客服</view>
							<view class="xiaohui">竭誠爲您服務~</view>
						</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="flexbetween mainpadding ffffff" style="margin-top: 40rpx;" @click="call()">
					<view class="flexleft">
						<image src="../../static/images/system/my6.png" mode="" class="headimg margin_right"></image>
						<view class="">
							<view class="titletext bold hei_text">電話客服</view>
							<view class="xiaohui">{{kf.kf_mobile}}</view>
						</view>
					</view>
					<u-icon name="arrow-right" color="#999" size="16"></u-icon>
				</view>
				<view class="mainpadding">
					<view class="submitbtn" @click="kefushow=false">確定</view>
				</view>
			</view>
		</u-popup>
		<tabbar ref="tabbarref" :current="5"></tabbar>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				kefushow: false,
				is_login: false,
				userInfo: {},
				shopStatus: 0, //0未提交商家審核 1已提交商家審核
				takeStatus: 0, //0未提交外送員審核 1已提交外送員審核
				numAll: {},
				status: 0, //0未提交實名認證，1已提交實名認證
				show: false,
				qrcodeurl_text: "",
				kf: {},
				bannerimgdata:{}
			}
		},
		onLoad() {
			uni.hideTabBar()
		},
		onShow() {
			this.$nextTick(() => {
				this.$refs.tabbarref.init()
			});
			this.is_login = httpRequest.checkIsLogin();
			console.log(this.is_login);
			if (this.is_login) {
				this.getUserInfo()
				this.getShopInfo()
				this.getTakeInfo()
				this.getruzhu()
				this.getnum()
				this.gettxt()
				this.getsmrzInfo()
				this.getfkurl()
				this.getbannerimg()
			} else {
				this.userInfo = null
			}
		},
		methods: {
			getbannerimg(){
				this.http.request('/api/index/getOnlyImage', 'GET', {
					data_type:3
				}).then(res=>{
					this.bannerimgdata = res.data
				})
			},
			call() {
				uni.makePhoneCall({
					phoneNumber: this.kf.kf_mobile //仅为示例
				});
			},
			kfgo() {
				console.log(this.kf.kf_link)
				location.href = this.kf.kf_link;
			},
			gettxt() {
				this.http.request("/api/index/getText", "GET", {
					type: 3
				}).then(res=>{
					this.kf = res.data
				})
			},
			getfkurl() {
				this.http.request("/api/member/getfukuan", 'POST', {}).then(res => {
					this.qrcodeurl_text = res.data + "?id=" + uni.getStorageSync("user_id")
				})
			},
			jumpurlfukuan(url) {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				if (!this.userInfo.paypass) {
					this.http.toast("請設置支付密碼")
					setTimeout(() => {
						uni.navigateTo({
							url: "/pages_mine/setpassword"
						})
					}, 1000)
					return false
				}
				uni.navigateTo({
					url
				})
			},
			diancan(){
				uni.navigateTo({
					url:"/pages_mine/zizhucan"
				})
			},
			shoukuan(){
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				this.show=true
			},
			goRecharge() { //儲值
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				uni.navigateTo({
					url: "/pages_mine/recharge"
				})
			},
			goWithdrawal() { //提領
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				uni.navigateTo({
					url: "/pages_mine/withdrawal"
				})
			},
			async getnum() { //獲取數量
				let _this = this
				let res = await this.http.request('/api/member/mycount', 'POST', {})
				if (res.code == 1) {
					this.numAll = res.data
				}
			},

			async getUserInfo() { //獲取個人信息
				let _this = this
				let res = await this.http.request('/api/member/userInfo', 'GET', {})
				if (res.code == 1) {
					res.data.avatar = this.imgUrl + res.data.avatar
					_this.userInfo = res.data
					uni.setStorageSync("invite_code",res.data.invite_code)
					console.log(this.imgUrl + res.data.avatar, "999");
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			getruzhu() { //獲取個人信息
				this.http.request('/api/shop/Shopdeail', 'GET', {}).then(res => {
					if (res.code == 1) {
						this.sjsh = res.data.status ? 1 : 0
					}
				})
			},
			async getShopInfo() { //獲取提交商家認證信息
				let _this = this
				let res = await this.http.request('/api/shop/Shopdeail', 'POST', {})
				if (res.code == 1) {
					this.shopStatus = 1
				} else if (res.code == 0) {
					this.shopStatus = 0
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			async getTakeInfo() { //獲取提交外送員認證信息
				let _this = this
				let res = await this.http.request('/api/Takeaway/Takedeail', 'GET', {})
				if (res.code == 1) {
					this.takeStatus = 1
				} else if (res.code == 0) {
					this.takeStatus = 0
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			goPersonInformation() { //個人信息
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				uni.navigateTo({
					url: "/pages_mine/personInformation"
				})
			},
			goLogin() {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			goMineCollect() { //我的收藏
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				uni.navigateTo({
					url: "/pages_mine/mineCollect"
				})
			},
			goTickets() { //我的票券
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				uni.reLaunch({
					url: "/pages/order/order?headerTabActive=4&tabActive=1"
				})
			},
			goMineCoupon() { //我的優惠券
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				uni.navigateTo({
					url: "/pages_mine/mineCoupon"
				})
			},
			gomianyun() {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				uni.navigateTo({
					url: "/pages_mine/minemyq"
				})
			},
			goFootprint() { //瀏覽記錄
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				uni.navigateTo({
					url: "/pages_mine/mineFootprint"
				})
			},
			goAssetManagement() { //資產管理
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				uni.navigateTo({
					url: "/pages_mine/assetManagement"
				})
			},
			goInvoice() { //發票
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				uni.navigateTo({
					url: "/pages_mine/invoice"
				})
			},
			async getsmrzInfo() { //獲取實名認證信息
				let _this = this
				let res = await this.http.request('/api/member/Idendeail', 'GET', {})
				if (res.code == 1) {
					this.status = 1
				} else if (res.code == 0) {
					this.status = 0
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			goShopSettle() { //商家入駐
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				if (!this.shopStatus) {
					uni.navigateTo({
						url: "/pages_mine/shopSettle"
					})
				} else {
					uni.navigateTo({
						url: "/pages_mine/examine"
					})
				}
			},
			goDeliverySettle() { //外送員入駐
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}

				if (this.userInfo.is_rz == 0) {

					if (this.status == 0) {
						this.http.toast('請先進行實名認證！');
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages_mine/realAuthentication"
							})
						}, 500)
					} else {
						this.http.toast('實名認證審核中！');
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages_mine/realAuthenticationExamine"
							})
						}, 500)
					}
					return false
				}
				if (this.takeStatus == 0) {
					uni.navigateTo({
						url: "/pages_mine/deliverySettle"
					})
				} else {
					uni.navigateTo({
						url: "/pages_mine/deliveryExamine"
					})
				}
			},
			goSetUp() { //設置
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false;
				}
				uni.navigateTo({
					url: "/pages_mine/setUp"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bannner {
		width: 100%;
		height: 220rpx;
	}
	.headimg {
		width: 100rpx;
		height: 100rpx;
		min-width: 100rpx;
	}
	.popupBox {
		padding-bottom: 50rpx;

		.headerImg {
			width: 658rpx;
			height: 237rpx;
		}

		.codeImg {
			width: 433rpx;
			height: 433rpx;
		}
	}

	.bannerimg {
		width: 80rpx;
		height: 80rpx;
	}

	.headerItem {
		width: 144rpx;
		height: 65rpx;
		text-align: center;
		line-height: 65rpx;
		border: 2rpx solid rgba(255, 255, 255, 1);
		border-radius: 10rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #360C00;
	}

	// 頭部
	.header {
		height: 533rpx;
		background-image: url("/static/images/index/header.png");
		background-size: 100% 100%;
		padding-top: 60rpx;

		// 用戶信息
		.avtarBox {
			width: 110rpx;
			height: 110rpx;
			border-radius: 50%;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
			}
		}

		// 收藏、票券、優惠券、瀏覽記錄
		.tabBox {
			padding: 15rpx 30rpx;
			background: rgba(255, 255, 255, 0.2);
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			border: 1rpx solid rgba(255, 255, 255, 0.8);

			.line {
				width: 0;
				height: 43rpx;
				border-right: 1rpx solid rgba(255, 255, 255, 0.4);
			}
		}
	}

	// 列表
	.actionBox {
		margin-top: 220rpx;

		.actionItem {
			padding: 30rpx 0;
		}

		.listImg {
			width: 38rpx;
			height: 38rpx;
			margin-right: 20rpx;
		}
	}
</style>